<?php
/**
 * @version		$Id: multisite.php 32 2009-08-17 14:47:55Z naveen.gavini $
 * @package		Joomla
 * @subpackage	Joomla Multisite
 * @copyright	Copyright (C) 2009 Open Source Matters. All rights reserved.
 * @license		GNU/GPL, see LICENSE.php
 * Joomla! is free software. This version may have been modified pursuant to the
 * GNU General Public License, and as distributed it includes or is derivative
 * of works licensed under the GNU General Public License or other free or open
 * source software licenses. See COPYRIGHT.php for copyright notices and
 * details.
 */

// No direct access
defined( '_JEXEC' ) or die( 'Restricted access' );

/**
 * Multisite Multisite Controller
 *
 * @package    Joomla Multisite
 * @subpackage Components
 */
class MultisitesControllerMultisite extends MultisitesController
{
	/**
	 * constructor (registers additional tasks to methods)
	 * @return void
	 */
	function __construct()
	{
		parent::__construct();

	}

	/**
	 * display the add form
	 * @return void
	 */
	function add()
	{
		JRequest::setVar( 'view', 'multisite' );
		JRequest::setVar( 'layout', 'default'  );
		JRequest::setVar('hidemainmenu', 1);

		parent::display();
	}

	/**
	 * display the edit form
	 * @return void
	 */
	function edit()
	{
		JRequest::setVar( 'view', 'multisite' );
		JRequest::setVar( 'layout', 'edit'  );
		JRequest::setVar('hidemainmenu', 1);

		parent::display();
	}

	/**
	 * save a record (and redirect to main page)
	 * @return void
	 */
	function save()
	{
		$model = $this->getModel('multisite');
		if ($model->store($post)){
			$msg = JText::_( 'Site Saved' );
		} else {
			$msg = JText::_( 'Error Saving Site' );
		}

		//Check the table in so it it can be edited.... we are done with it anyway
		$link = 'index.php?option=com_multisite';
		$this->setRedirect($link, $msg);
	}

	/**
	 * save an edited record (and redirect to main page)
	 * @return void
	 */
	function saveEdit()
	{
		$model = $this->getModel('multisite');
		if ($model->storeEdit($post)){
			$msg = JText::_( 'Site Saved' );
		} else {
			$msg = JText::_( 'Error Saving Site' );
		}

		//Check the table in so it it can be edited.... we are done with it anyway
		$link = 'index.php?option=com_multisite';
		$this->setRedirect($link, $msg);
	}

	/**
	 * remove record(s)
	 * @return void
	 */
	function remove()
	{
		$model = $this->getModel('multisite');
		if(!$model->delete()) {
			$msg = JText::_( 'Error: One or More Sites Could not be Deleted' );
		} else {
			$msg = JText::_( 'Site(s) Deleted' );
		}

		$this->setRedirect( 'index.php?option=com_multisite', $msg );
	}

	/**
	 * sync page for a site
	 * @return void
	 */
	function sync()
	{
		JRequest::setVar( 'view', 'multisite' );
		JRequest::setVar( 'layout', 'sync'  );
		JRequest::setVar('hidemainmenu', 1);

		parent::display();
	}

	/**
	 * sync site with other sites
	 * @return void
	 */
	function saveSync()
	{
		$model = $this->getModel('multisite');
		if ($model->syncSave($post)){
			$msg = JText::_( 'All tables Synced' );
		} else {
			$msg = JText::_( 'Error Syncing' );
		}

		//Check the table in so it it can be edited.... we are done with it anyway
		$link = 'index.php?option=com_multisite';
		$this->setRedirect($link, $msg);
	}

	/**
	 * cancel current operation
	 * @return void
	 */
	function cancel()
	{
		$msg = JText::_( 'Operation Cancelled' );
		$this->setRedirect( 'index.php?option=com_multisite', $msg );
	}

	/**
	 * view help page
	 * @return void
	 */
	function help()
	{
		JRequest::setVar( 'view', 'multisite' );
		JRequest::setVar( 'layout', 'help'  );
		JRequest::setVar('hidemainmenu', 1);

		parent::display();
	}
}